<?php
use yii\helpers\Url;
$this->context->layout = false;
?>
<?php
//使用率
echo $this->render("@app/views/public/useRate.php")
?>
<div id="History-List"></div>
<script type="text/x-kendo-template" id="HistoryTemplate">
    <a class="k-button k-button-icontext btn btn-info btn-lg active" onclick="onHistory()"><span class="glyphicon glyphicon-align-justify"></span>修改历史</a>
    <a class="k-button k-button-icontext"   onclick="onDestroyHistory()"><span class="glyphicon glyphicon-align-justify"></span>删除历史</a>
    <input type="text" id="h_date_month"  name="h_date_month" value="<?=$date?>" placeholder="月份">
    <span id="HistoryDeductions"></span>
</script>
<script>
    var History_grid = $("#History-List");
    $(document).ready(function() {
        History_grid.kendoGrid({
            dataSource: {
                transport: {
                    read:function (e) {
                        $.ajax({
                            url: "<?=Url::to(['historylist','h_date_month'=>'']); ?>"+$("#h_date_month").val(),
                            dataType: "json",
                            success:function (redata) {
                                e.success(redata);
                            }
                        })
                    }
                },
                schema: {
                    model: {
                        fields: {
                            created: { field:"created",type:"date"},
                            modify: { field:"modify",type:"date"},
                            modifyBy: { field:"modifyBy"},
                            createBy: { field:"createBy"},
                            typeName: { field:"typeName"},
                            level1Name: { field:"level1Name"},
                            level2Name: {field:"level2Name"},
                            content: {field:"content"}
                        }
                    }
                },
                pageSize: 20
            },
            sortable: true,
            filterable: {
                extra: false,
                operators: {
                    string: {
                        contains: "包含",
                        doesnotcontain: "不包含",
                        eq: "等于",
                        neq: "不等于"
                    }
                }
            },
            toolbar:kendo.template($("#HistoryTemplate").html()),
            pageable:{
                refresh: true,
                pageSizes: [20, 40, 60, "all"],
                buttonCount: 5
            },
            columns: [
                {
                    field:"modify",
                    title: "修改时间(美国)" ,
                    template:function (e) {
                        if (typeof e.pid =='string'){
                            return "";
                        }
                        return e.modify.Format("yyyy-MM-dd hh:mm");
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field:"created",
                    title: "发布时间(美国)" ,
                    template:function (e) {
                        if (typeof e.pid =='string'){
                            return "";
                        }
                        return e.created.Format("yyyy-MM-dd hh:mm");
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field:"department_name",
                    title:"部门",
                    template:function (e) {
                        if (typeof e.pid =='string'){
                            return "";
                        }
                        return e.department_name;
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field:"group_name",
                    title:"组别",
                    template:function (e) {
                        if (typeof e.pid =='string'){
                            return "";
                        }
                        return e.group_name;
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "modifyBy",
                    title:"修改人" ,
                    template:function (e) {
                        if (typeof e.pid =='string'){
                            return "";
                        }
                        return e.modifyBy;
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "createBy",
                    title:"被修改人" ,
                    template:function (e) {
                        if (typeof e.pid =='string'){
                            return "";
                        }
                        return e.createBy;
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    title:"STATUS" ,
                    template:function (e) {
                        if (typeof e.pid =='string'){
                            return "修改后";
                        }
                        return "修改前";
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field:"typeName",
                    title:"五大类" ,
                    template:function (e) {
                        if (typeof e.modifyStatus =='string'&&e.modifyStatus.indexOf('4')>-1){
                            return "<span style='background:yellow'>"+e.typeName+"</span>";
                        }
                        if (typeof e.typeName == 'object')
                            return "";
                        return e.typeName;
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field:"column",
                    title:"三类别" ,
                    template:function (e) {
                        if (typeof e.modifyStatus =='string'&&e.modifyStatus.indexOf('5')>-1){
                            return "<span style='background:yellow'>"+e.column+"</span>";
                        }
                        if (typeof e.typeName == 'object')
                            return "";
                        return e.column;
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "level1Name",
                    title:"错误一级类别" ,
                    template:function (e) {
                        if (typeof e.modifyStatus =='string'&&e.modifyStatus.indexOf('1')>-1){
                            return "<span style='background:yellow'>"+e.level1Name+"</span>";
                        }
                        return e.level1Name;
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "level2Name",
                    title:"错误二级类别" ,
                    template:function (e) {
                        if (typeof e.modifyStatus =='string'&&e.modifyStatus.indexOf('2')>-1){
                            return "<span style='background:yellow'>"+e.level2Name+"</span>";
                        }
                        return e.level2Name;
                    },
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "content",
                    title:"详情" ,
                    template:function (e) {
                        if (typeof e.modifyStatus =='string'&&e.modifyStatus.indexOf('3')>-1){
                            return "<span style='background:yellow'>"+e.content+"</span>";
                        }
                        return e.content;
                    },
                    width:"30%"
                }
            ]

        });
        $("#h_date_month").kendoDatePicker({
            start: "year",
            depth: "year",
            format: "yyyy/MM",
            change:function(e){
                var __grid = History_grid.data("kendoGrid");
                __grid.dataSource.read();
                __grid.refresh();
            }
        });
    });
    Date.prototype.Format = function (fmt){
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }
</script>
